import pymysql

class MyORM:
    def __init__(self):
        # 建立与数据库的连接
        conn = pymysql.connect(
            host="192.168.1.129",
            port=3306,
            user="admin1",
            password="123",
            database="mumushouji",
            charset="utf8",
            cursorclass=pymysql.cursors.DictCursor,
            autocommit=True
        )
        # 实例化一个游标对象
        cursor = conn.cursor()
        self.cursor = cursor

    def execute(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()

class User:
    table_name = "user"
    def query_all(self):
        sql = "select * from %s" % (self.table_name)
        return MyORM().execute(sql)
    def query_one(self):
        sql = "select * from %s limit 1" % (self.table_name)
        return MyORM().execute(sql)

class Article:
    table_name = "article"
    def query_all(self):
        sql = "select * from %s limit 2" % (self.table_name)
        return MyORM().execute(sql)
    def query_one(self):
        sql = "select * from %s limit 1" % (self.table_name)
        return MyORM().execute(sql)

if __name__ == "__main__":
    user = User()
    r = user.query_all()
    print(r)
    article = Article()
    r2 = article.query_all()
    print(r2)
    print(user.query_one())
    print(article.query_one())